{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## algorithm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def eratosthenes(n):\n",
    "    n = (n + 1) >> 1\n",
    "    p = np.ones(n, dtype=np.int8)\n",
    "    i, j = 1, 3\n",
    "    \n",
    "    while i < n:\n",
    "        if p[i]:\n",
    "            p[j * j >> 1::j] = 0\n",
    "        i, j = i + 1, j + 2\n",
    "\n",
    "    return p.sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 4\n",
      "100 25\n",
      "1000 168\n",
      "10000 1229\n",
      "100000 9592\n",
      "1000000 78498\n",
      "10000000 664579\n"
     ]
    }
   ],
   "source": [
    "for j in range(1, 8):\n",
    "    print(10 ** j, eratosthenes(10 ** j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
